import java.io.PrintWriter;
import java.io.StringWriter;

import javax.swing.JButton;
import javax.swing.JOptionPane;

import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.view.JRViewer;

	class MyViewer extends JRViewer {

		private static final long serialVersionUID = -5746056340680371146L;
		private JButton btnPlus;

		public MyViewer(final JasperPrint jrPrint) {
			super(jrPrint);
			//tlbToolBar.remove(btnSave);
			tlbToolBar.remove(btnReload);
			//tlbToolBar.remove(this.btnPrint);
			btnPlus = new javax.swing.JButton();
			btnPlus.setToolTipText("พิมพ์");
			btnPlus.setText("พิมพ์");
			btnPlus.setPreferredSize(new java.awt.Dimension(80, 23));
			btnPlus.setMaximumSize(new java.awt.Dimension(80, 23));
			btnPlus.setMinimumSize(new java.awt.Dimension(80, 23));
			btnPlus.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent evt) {
					Thread thread = new Thread(new Runnable() {
						public void run() {
							try {
								JasperPrintManager.printReport(jrPrint, false);
							} catch (Exception e) {
								StringWriter swriter = new StringWriter();
								PrintWriter pwriter = new PrintWriter(swriter);
								e.printStackTrace(pwriter);
								JOptionPane.showMessageDialog(MyViewer.this,
										swriter.toString());
							}
						}
					});

					thread.start();
				}
			});
			tlbToolBar.add(btnPlus, 0);
		}

	}
